package com.zsy.petshop_01.controller;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "订单管理接口")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

    @ApiOperation("单页查询订单信息")
    @GetMapping("selectPageOrder")
    public ResponseResult<?> selectPageOrder(@RequestParam("currentPage") Integer currentPage,
                                             @RequestParam("pageSize") Integer pageSize,
                                             @RequestParam(value = "userId", required = false) Integer userId,
                                             @RequestParam(value = "time", required = false) String time,
                                             @RequestParam(value = "isDispose", required = false) Boolean isDispose,
                                             @RequestParam(value = "isAccomplish", required = false) Boolean isAccomplish) {
        return orderService.selectPageOrder(currentPage, pageSize, userId, time, isDispose, isAccomplish);
    }

    @ApiOperation("单页查询用户订单信息")
    @GetMapping("selectPageUserOrder")
    public ResponseResult<?> selectPageUserOrder(@RequestParam("currentPage") Integer currentPage,
                                                 @RequestParam("pageSize") Integer pageSize,
                                                 @RequestParam(value = "time", required = false) String time,
                                                 @RequestParam(value = "isDispose", required = false) Boolean isDispose,
                                                 @RequestParam(value = "isAccomplish", required = false) Boolean isAccomplish,
                                                 HttpServletRequest request) {
        return orderService.selectPageUserOrder(currentPage, pageSize, time, isDispose, isAccomplish, request);
    }

    @ApiOperation("处理订单")
    @PostMapping("disposeOrder")
    public ResponseResult<?> disposeOrder(@RequestParam("id") Integer id) {
        return orderService.disposeOrder(id);
    }

    @ApiOperation("完成订单")
    @PostMapping("accomplishOrder")
    public ResponseResult<?> accomplishOrder(@RequestParam("id") Integer id) {
        return orderService.accomplishOrder(id);
    }

    @ApiOperation("取消订单")
    @PostMapping("cancelOrder")
    public ResponseResult<?> cancelOrder(@RequestParam("id") Integer id,@RequestParam("reason") String reason) {
        return orderService.cancelOrder(id,reason);
    }
}
